import router from './router'

const whiteList = ['/login'] // no redirect whitelist
import config from './config';
import { useUserStore } from './store/user';

router.beforeEach(async (to, from, next) => {

  const hasToken = getToken()
  let  userStore  = useUserStore()
  console.log('userStore:id', userStore.id)

  if (hasToken) {
    if (to.path === '/login') {
      // if is logged in, redirect to the home page
      next({ path: config.homePage })
    }
    // your permission code


    next()


    

  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      // in the free login whitelist, go directly
      next()
    } else {
      // other pages that do not have permission to access are redirected to the login page.
      next(`/login?redirect=${to.path}`)
    }
  }
})
